import Vue from 'vue';
import Router from 'vue-router';
import { Util } from '@/assets/commonjs/utils.js';
// import store from '../store/index';
// import { resolve } from 'url';

const notFoundPage = () => import('@/views/404Page');
const Welcome = () => import('@/views/welcome');
const UploadWgt = () => import('@/views/uploadWgt');


//淘金区
const PanGold = () => import('@/views/pan-gold/index.vue');
const Service = () => import('@/views/service/index.vue');
const My = () => import('@/views/my/index.vue');
const Index = () => import('@/views/index/index.vue');
const Find = () => import('@/views/find/index.vue');
const FindDetails = () => import('@/views/find/FindDetails.vue');
const Center = () => import('@/views/center/index.vue');

// 节点算力
const Hashrate = () => import('@/views/hashrate/index.vue');
const HashrateDetail = () => import('@/views/hashrate/detail.vue');

// 交易中心
const Transaction = () => import('@/views/transaction/index.vue');
const NewBill = () => import('@/views/transaction/newbill.vue');
const Listcentre = () => import('@/views/transaction/listcentre.vue');
const Sell = () => import('@/views/transaction/sell.vue');
const Buy = () => import('@/views/transaction/buy.vue');
const BillDetails = () => import('@/views/transaction/billDetails.vue');
const Mybuylist = () => import('@/views/transaction/mybuylist.vue');


// 首页模块  --start
//申诉
const Appeal = resolve => require(['@/views/pan-gold/appeal.vue'], resolve)
const NoticeDetail = resolve => require(['@/views/pan-gold/noticeDetail.vue'], resolve)
const Notice = resolve => require(['@/views/pan-gold/notice.vue'], resolve)
// 淘金区模块  --end


//客服中心
const Customer = resolve => require(['@/views/service/customer.vue'], resolve)
const Help = resolve => require(['@/views/service/help.vue'], resolve)
const Problem = resolve => require(['@/views/service/problem.vue'], resolve)
const QuestionDetails = resolve => require(['@/views/service/question-details.vue'], resolve)
const QuestionList = resolve => require(['@/views/service/question-list.vue'], resolve)


// 服务  ----start

// 服务  ----end



// 我的  --start
const Invite = resolve => require(['@/views/my/nav/invite.vue'], resolve);
const Set = resolve => require(['@/views/my/set.vue'], resolve);
const CheckUpdate = resolve => require(['@/views/my/checkUpdate.vue'], resolve)
const About = resolve => require(['@/views/center/about.vue'], resolve)
const Exchange = resolve => require(['@/views/center/exchange.vue'], resolve)
const ExchangeRecord = resolve => require(['@/views/center/exchangeRecord.vue'], resolve)
const RechargeRecord = resolve => require(['@/views/center/rechargeRecord.vue'], resolve)
const Withdraw = resolve => require(['@/views/center/withdraw.vue'], resolve)
const ModifyPay = resolve => require(['@/views/my/modifyPay.vue'], resolve);
const RobotDetail = resolve => require(['@/views/center/robotDetail.vue'], resolve);
const Upgrade = resolve => require(['@/views/center/upgrade.vue'], resolve);
const ServiceMessage = resolve => require(['@/views/center/serviceMessage.vue'], resolve);
const CustomerService = resolve => require(['@/views/center/customerService.vue'], resolve);
const ViewQuestions = resolve => require(['@/views/center/viewQuestions.vue'], resolve);
const MyTeam = resolve => require(['@/views/center/team.vue'], resolve);
const Assets = resolve => require(['@/views/center/assets.vue'], resolve);
const SaveMoney = resolve => require(['@/views/center/save-money.vue'], resolve);
const SaveRecord = resolve => require(['@/views/center/saveRecord.vue'], resolve);
const CashAddress = resolve => require(['@/views/center/cashAddress.vue'], resolve);
const Full = resolve => require(['@/views/center/full.vue'], resolve);
const CenterRecord = resolve => require(['@/views/center/record.vue'], resolve);
const Setmeal = resolve => require(['@/views/center/setmeal.vue'], resolve);
const MealDetails = resolve => require(['@/views/center/mealDetails.vue'], resolve);
const UpLevel = resolve => require(['@/views/center/uplevel.vue'], resolve);
const Message = resolve => require(['@/views/center/message.vue'], resolve);
const newMessage = resolve => require(['@/views/center/newMessage.vue'], resolve);
const Selected = resolve => require(['@/views/center/selected.vue'], resolve);
const Convert = resolve => require(['@/views/center/convert.vue'], resolve);
const AssetsDetails = resolve => require(['@/views/center/assetsDetails.vue'], resolve);
const Earnings = resolve => require(['@/views/center/earnings.vue'], resolve);
const PayInfo = resolve => require(['@/views/my/nav/pay/index.vue'], resolve);
const AddCard = resolve => require(['@/views/my/nav/pay/add-card.vue'], resolve);
const Bind = resolve => require(['@/views/my/nav/pay/bind.vue'], resolve);
// 我的  --end


// 用户相关  -start
const SetPwd = resolve => require(['@/views/init/set-pwd.vue'], resolve);
const Login = resolve => require(['@/views/init/login.vue'], resolve);
const BackPwd = resolve => require(['@/views/init/back-pwd.vue'], resolve);
const Register = resolve => require(['@/views/init/register.vue'], resolve);

// 用户相关  -end

// 下载
const Download = resolve => require(['@/views/download.vue'], resolve)

Vue.use(Router);
let routes = [
    {
        path: '/',
        // redirect: { name: 'Index' }
        redirect: { name: 'Transaction' }
    },
    {
        path: '/welcome',
        name: 'Welcome',
        component: Welcome
    },
    {
        path: '/uploadwgt',
        name: 'UploadWgt',
        component: UploadWgt
    },
    {
        path: '/index',
        name: 'Index',
        component: Index
    },
    {
        path: '/center',
        name: 'Center',
        component: Center
    },
    {
        path: '/find',
        name: 'Find',
        component: Find
    },
    {
        path: '/findDetails',
        name: 'FindDetails',
        component: FindDetails
    },


    //淘金区
    {
        path: '/pan-gold',
        name: 'PanGold',
        component: PanGold
    },
    {
        path: '/service',
        name: 'Service',
        component: Service
    },
    {
        path: '/my',
        name: 'My',
        component: My
    },
    {
        path: '/invite',
        name: 'Invite',
        component: Invite
    },
    {
        path: '/set',
        name: 'Set',
        component: Set
    },
    {
        path: '/setpwd',
        name: 'SetPwd',
        component: SetPwd
    },
    {
        path: '/login',
        name: 'Login',
        component: Login
    },
    {
        path: '/backpwd',
        name: 'BackPwd',
        component: BackPwd
    },
    {
        path: '/modifyPay',
        name: 'ModifyPay',
        component: ModifyPay
    },
    {
        path: '/robotDetail/:id',
        name: 'RobotDetail',
        component: RobotDetail
    },
    {
        path: '/upgrade/:id',
        name: 'Upgrade',
        component: Upgrade
    },
    {
        path: '/serviceMessage',
        name: 'ServiceMessage',
        component: ServiceMessage
    },
    {
        path: '/customerService',
        name: 'CustomerService',
        component: CustomerService
    },
    {
        path: '/viewQuestions/:id',
        name: 'ViewQuestions',
        component: ViewQuestions
    },
    {
        path: '/myteam',
        name: 'MyTeam',
        component: MyTeam
    },
    {
        path: '/message',
        name: 'Message',
        component: Message
    },
    {
        path: '/newMessage',
        name: 'newMessage',
        component: newMessage
    },
    {
        path: '/selected',
        name: 'Selected',
        component: Selected
    },
    {
        path: '/convert',
        name: 'Convert',
        component: Convert
    },
    {
        path: '/assetsDetails',
        name: 'AssetsDetails',
        component: AssetsDetails
    },
    {
        path: '/earnings',
        name: 'Earnings',
        component: Earnings
    },
    {
        path:'/payinfo',
        name:'PayInfo',
        component:PayInfo
    },
    {
        path:'/addcard',
        name:'AddCard',
        component:AddCard
    },
    {
        path:'/bind/:type',
        name:'Bind',
        component:Bind
    },
    {
        path: '/assets',
        name: 'Assets',
        component: Assets
    },
    {
        path: '/save-money',
        name: 'SaveMoney',
        component: SaveMoney
    },
    {
        path: '/saveRecord',
        name: 'SaveRecord',
        component: SaveRecord
    },
    {
        path: '/cashAddress',
        name: 'CashAddress',
        component: CashAddress
    },
    {
        path: '/full',
        name: 'Full',
        component: Full
    },
    {
        path: '/center/record',
        name: 'CenterRecord',
        component: CenterRecord
    },
    {
        path: '/center/setmeal',
        name: 'Setmeal',
        component: Setmeal
    },
    {
        path: '/center/mealDetails',
        name: 'MealDetails',
        component: MealDetails
    },
    {
        path: '/center/uplevel',
        name: 'UpLevel',
        component: UpLevel
    },
    {
        path: '/register',
        name: 'Register',
        component: Register
    },
    {
        path: '/pan-gold/notice',
        name: 'Notice',
        component: Notice
    },
    {
        path: '/pan-gold/appeal',
        name: "Appeal",
        component: Appeal
    },
    {
        path: '/pan-gold/noticeDetail/:id',
        name: "NoticeDetail",
        component: NoticeDetail
    },
    {
        path: '/my/checkupdate',
        name: "CheckUpdate",
        component: CheckUpdate
    },
    {
        path: '/center/about',
        name: "About",
        component: About
    },


    //客服中心
    {
        path: '/service/customer',
        name: 'Customer',
        component: Customer
    },
    {
        path: '/service/help',
        name: 'Help',
        component: Help
    },
    {
        path: '/service/problem',
        name: 'Problem',
        component: Problem
    },
    {
        path: '/service/question-details',
        name: 'QuestionDetails',
        component: QuestionDetails
    },
    {
        path: '/service/question-list',
        name: 'QuestionList',
        component: QuestionList
    },

    {
        path: '/download',
        name: 'Download',
        component: Download
    },
    {
        path: '/exchange',
        name: 'Exchange',
        component: Exchange
    },
    {
        path: '/exchangeRecord',
        name: 'ExchangeRecord',
        component: ExchangeRecord
    },
    {
        path: '/rechargeRecord',
        name: 'RechargeRecord',
        component: RechargeRecord
    },
    {
        path: '/withdraw',
        name: 'Withdraw',
        component: Withdraw
    },
    {
        path: '/hashrate',
        name: 'Hashrate',
        component: Hashrate
    },
    {
        path: '/hashrate/detail',
        name: 'HashrateDetail',
        component: HashrateDetail
    },
    {
        path: '/transaction/index',
        name: 'Transaction',
        component: Transaction
    },
    {
        path: '/transaction/newBill',
        name: 'NewBill',
        component: NewBill
    },
    {
        path: '/transaction/listcentre',
        name: 'Listcentre',
        component: Listcentre
    },
    {
        path: '/transaction/sell',
        name: 'Sell',
        component: Sell
    },
    {
        path: '/transaction/buy',
        name: 'Buy',
        component: Buy
    },
    {
        path: '/transaction/billDetails',
        name: 'BillDetails',
        component: BillDetails
    },
    {
        path: '/transaction/mybuylist',
        name: 'Mybuylist',
        component: Mybuylist
    },





    {
        path: '*',
        name: '404Page',
        component: notFoundPage
    }
];
// routes = routes.concat(myCenterRouter);

let router = new Router({
    mode: "hash",
    routes: routes
});
router.beforeEach((to, from, next) => {
    if (localStorage.getItem('cookie')) {
        if (Util.isWhite(to.name)) {
            if (to.name == 'Login') {
                next({ name: 'Transaction' })
                // next({ name: 'PanGold' })
            } else {
                next({ name: from.name });
            }
        } else {
            next();
        }
    } else {
        if (Util.isWhite(to.name)) {
            next();
        } else {
            next({ name: 'Login' });
            // next({name:'Welcome'});
        }
    }
});

// router.beforeEach((to,from,next)=>{
//     if(localStorage.getItem('vip') ||to.name =='Login'){
//         next()
//     }else {
//         next({name:'Login'});
//     }
// });
export default router;
